﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OneShoppingDAL;
using OneShoppingBLL;
using OneShoppingUtility;
using OneShoppingModel;

public partial class Backstage_Pages_sysmng_roleAdd : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (role.RoleId != 1)
        {
            Response.Redirect("login.html");
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string name = rolename.Text.Trim();
        if(name.Length==0)
        {
            msg_name.InnerText = "角色名称不能为空";
            msg_name.Visible = true;
            return;
        }
        Role r = RoleBLL.GetInstance().GetEntity(k => k.RoleName == name);
        if(r!=null)
        {
            msg_name.InnerText = "角色名称已存在";
            msg_name.Visible = true;
            return;
        }
        Role role = new Role
        {
            RoleName=name,
            IsUsing=1
        };
        bool rr = RoleBLL.GetInstance().Insert(role);
        if(rr)
        {
            UtilityMessageBox.ShowAndRedirect(this, "添加角色成功", "roleManager.aspx");
        }
        else
        {
            UtilityMessageBox.ShowAndRedirect(this, "添加角色失败", "roleManager.aspx");
        }
    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("roleManager.aspx");
    }
}